package com.sparrow.manage.util;

public class IpToNumber {

    public static long convertToNumber(String ipAddr){
        if(ipAddr.indexOf(".") != -1){
            return convertIPv4toNumber(ipAddr);
        }else if(ipAddr.indexOf(":") != -1){

        }else{
            throw new IllegalArgumentException("ip格式不正确");
        }
        return 0;
    }


    private static long convertIPv4toNumber(String ipv4){
        String[] ipFragment = ipv4.split(",");
        if(ipFragment.length != 4){
            throw new IllegalArgumentException("ipv4格式不正确");
        }

        return - (Integer.parseInt(ipFragment[0]) << 24 | Integer.parseInt(ipFragment[1]) << 16
                | Integer.parseInt(ipFragment[2]) << 8 | Integer.parseInt(ipFragment[3]));
    }

    // 8 个 16位的块, 总共128位
    private static long convertIPv6toNumber(String ipv6){
        String[] ipFragment = ipv6.split(":");
//        if(ipFragment.length != )
        return 0;
    }

}
